<template>
	<view>
		<view class="u-p-l-30 u-p-b-30 u-p-r-30 bg-white">
			<view class="u-flex">
				<!-- <view class="u-m-r-20 filter-bar">
					<u-icon name="hourglass-half-fill" :size="30"></u-icon>
					<text class="u-p-r-40">筛选</text>
					<u-icon name="arrow-down-fill" :size="20"></u-icon>
				</view> -->
				<view class="u-flex-1">
					<u-search v-model="key" :show-action="false" placeholder="搜索订单" shape="square" clearabled @change="searchKeyword"></u-search>
				</view>
			</view>
		</view>
		<!-- <view class="bg-white">
			<u-dropdown ref="uDropdown" @open="open" @close="close" :title-size="28" :active-color="'#10beca'">
				<u-dropdown-item v-model="timeType" title="下单时间" :options="options1" @change="dropdownChange(timeType,1)"></u-dropdown-item>
				<u-dropdown-item v-model="id" title="订单分类" :options="cityArr" @change="dropdownChange(value2,2)" height="70vh"></u-dropdown-item>
			</u-dropdown>
		</view> -->
		<!-- <view class="total-weight bg-white u-p-b-30">
			<view class="grid-box u-m-t-0 u-p-0" style="box-shadow: none;">
				<view class="u-flex">
					<view class="cell u-flex-1" style="background: #e83e8c14;">
						<view class="number"><text class="u-font-40">{{recovery.weight}}</text></view>
						<view class="title u-font-24">总重量(KG)</view>
					</view>
					<view class="divider"></view>
					<view class="cell u-flex-1" style="background: #28a74517;">
						<view class="number"><text class="u-font-40">{{recovery.count}}</text></view>
						<view class="title u-font-24">订单数(条)</view>
					</view>
					<view class="divider"></view>
					<view class="cell u-flex-1" style="background: #007bff17;">
						<view class="number"><text class="u-font-40">{{recovery.regcount}}</text></view>
						<view class="title u-font-24">注册人数(人)</view>
					</view>
				</view>
			</view>
		</view> -->
		
		<!-- 订单列表 -->
		<view class="page-box" v-for="(res, index) in orderList" :key="res.id">
			<navigator class="order" :url="goDetails(res)">
				<view class="top">
					<view class="left">
						<u-tag text="自送" mode="light" type="warning" size="mini" v-if="res.terminal == 'AIO'"/>
						<!-- <u-icon name="order" :size="30" color="rgb(94,94,94)" v-else></u-icon> -->
						<view class="store u-m-l-0">{{res.number}}</view>
					</view>
					<view class=""><u-icon name="arrow-right" class="u-tips-color"></u-icon></view>
				</view>
				<!-- 上门地址与联系人 -->
				<view class="u-p-t-20" v-if="res.address">
					<view class="address">
						<u-icon name="map-fill" size="32"></u-icon>
						<text class="u-font-32">【{{res.address.cityname}}】{{res.address.address}}</text>
					</view>
					<view class="u-p-t-8">
						<view class="u-flex u-font-24">
							<text class="u-text-right">{{res.address.name}}</text>
							<text class="u-p-l-30">{{res.address.mobile}}</text>
						</view>
					</view>
				</view>
				
				<view class="time">
					<view class="u-flex" v-if="res.user">
						<text class="label u-tips-color">下单用户</text>
						<text class="u-flex-1 u-text-right u-font-28 bold">{{res.user.name}}</text>
					</view>
					<view class="u-flex" v-if="res.enterprise">
						<text class="label u-tips-color">下单用户</text>
						<text class="u-flex-1 u-text-right u-font-28 bold">{{res.enterprise.name}}</text>
					</view>
					<view class="u-flex" v-if="res.weight > 0">
						<text class="label u-tips-color">回收重量</text>
						<text class="u-flex-1 u-text-right u-font-28 bold">{{res.weight}}</text>
						<text>KG</text>
					</view>
					<view class="u-flex" v-if="res.quantity > 0">
						<text class="label u-tips-color">回收件数</text>
						<text class="u-flex-1 u-text-right u-font-28">{{res.quantity}}</text>
						<text>件</text>
					</view>
					<view class="u-flex" v-if="res.completiontime">
						<text class="label u-tips-color">收货时间</text>
						<text class="u-flex-1 u-text-right u-font">{{res.completiontime}}</text>
					</view>
				</view>
				
				<view class="bottom">
					<view class="more">
						<text class="u-font-24 u-tips-color">{{$u.timeFrom(new Date(res.createddatetime.replaceAll('-','/')), false)}}</text>
					</view>
					<view class="total">
						<template>
							<text class="u-p-l-15">合计:</text>
							<text class="total-price">
								<text>￥</text>
								<text class="decimal bold">{{ res.amount.toFixed(2) }}</text>
							</text>
						</template>
					</view>
				</view>
			</navigator>
		</view>
		<view class="u-p-30">
			<u-loadmore :status="loadStatus"></u-loadmore>
		</view>
		<!-- 筛选弹窗 -->
		<!-- <u-popup v-model="filterShow" mode="bottom" border-radius="14" :closeable="true" z-index="100">
			<view class="filter-box u-p-60">
				<view class="u-text-center">数据筛选</view>
				<view class="item">
					<view class="item-head">社区名称</view>
					<view class="item-option">
						<view class="on">全部</view>
					</view>
				</view>
			</view>
		</u-popup> -->
		
		<!-- 自定义时间范围选择 -->
		<!-- <u-calendar v-model="calendarTime" mode="range" active-bg-color="rgb(16,190,202)" range-bg-color="rgba(16,190,202,0.13)" range-color="rgb(16,190,202)" @change="calendarChange"></u-calendar> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				type: 0,
				cityId: 0,
				timeType: 0,
				startDate: '',
				endDate: '',
				enterprisetype: [],
				
				// typeId: null,
				// storeareaid: 0,
				key: '',
				PageIndex: 1,
				PageSize: 20,
				loadStatus: 'loading',
				recovery: {
					count: 0,
					regcount: 0,
					weight: 0
				},
				orderList: [
					
				],
				/* 筛选 */
				// filterShow: false,
				// 下单时间
				// timeType: 0,
				// options1:[
				// 	{
				// 		value: 0,
				// 		label: '全部'
				// 	},
				// 	{
				// 		value: 1,
				// 		label: '今日'
				// 	},
				// 	{
				// 		value: 2,
				// 		label: '昨日'
				// 	},
				// 	{
				// 		value: 3,
				// 		label: '本月'
				// 	},
				// 	{
				// 		value: 4,
				// 		label: '上月'
				// 	},
				// 	{
				// 		value: 5,
				// 		label: '本季度'
				// 	},
				// 	{
				// 		value: 6,
				// 		label: '上季度'
				// 	},
				// 	{
				// 		value: 7,
				// 		label: '本年'
				// 	},
				// 	{
				// 		value: 8,
				// 		label: '上年'
				// 	},
				// 	{
				// 		value: 9,
				// 		label: '自定义'
				// 	}
				// ],
				// calendarTime: false,
				// startDate: '',
				// endDate: '',
				// 社区名称
				// value2: 0,
				// cityArr: [
				// 	{
				// 		value: 0,
				// 		label: '全部'
				// 	}
				// ],
				// 下单站点
				// value3: 0,
				// options3: [
				// 	{
				// 		value: 0,
				// 		label: '全部'
				// 	}
				// ]
			}
		},
		onLoad(opt) {
			console.log('接收的参数:',opt)
			this.id = opt.id
			this.type = opt.type
			this.cityId = opt.cityId
			this.timeType = opt.timeType || 0
			this.startDate = opt.startDate
			this.endDate = opt.endDate
			this.enterprisetype = opt.enterprisetype || []
			// this.getCitys(this.type).then(()=>{
			// 	let title = this.cityArr.find((item)=>item.value == this.id).label
			// 	uni.setNavigationBarTitle({
			// 		title: title + '订单数据'
			// 	});
			// })

			this.getDataBoardDetails()
		},
		onPullDownRefresh() {
			this.orderList = []
			this.PageIndex = 1
			this.getDataBoardDetails().finally(()=>{
				uni.stopPullDownRefresh(); //停止当前页面下拉刷新
			})
		},
		onReachBottom(){
			this.PageIndex += 1
			this.getDataBoardDetails(false)
		},
		methods: {
			// open(index) {
			// 	// 展开某个下来菜单时，先关闭原来的其他菜单的高亮
			// 	// 同时内部会自动给当前展开项进行高亮
			// 	this.$refs.uDropdown.highlight();
			// },
			// close(index) {
			// 	// 关闭的时候，给当前项加上高亮
			// 	// 当然，您也可以通过监听dropdown-item的@change事件进行处理
			// 	this.$refs.uDropdown.highlight(index);
			// },
			// dropdownChange(value,type){
			// 	// 下拉筛选选择回调
			// 	console.log(value,type)
			// 	switch (type){
			// 		case 1:
			// 			// 下单时间
			// 			console.log('筛选下单时间')
			// 			if(value == 9){
			// 				this.calendarTime = true
			// 			} else {
			// 				this.getDataBoardDetails()
			// 			}
			// 			break;
			// 		case 2:
			// 			// 社区名称
			// 			console.log('筛选社区名称')
			// 			this.cityId = value
			// 			let title = this.cityArr.find((item)=>item.value == this.id).label
			// 			uni.setNavigationBarTitle({
			// 				title: title + '订单数据'
			// 			});
			// 			this.getDataBoardDetails()
			// 			break;
			// 		default:
			// 			// // 下单站点
			// 			// console.log('筛选下单站点')
			// 			// this.getDataBoardDetails()
			// 			break;
			// 	}
			// },
			// calendarChange(e){
			// 	// 选择自定义时间范围
			// 	console.log(e);
			// 	this.startDate = e.startDate
			// 	this.endDate = e.endDate
			// 	this.getDataBoardDetails()
			// },
			searchKeyword(val) {
				this.key = val
				this.PageIndex = 1;
				this.getDataBoardDetails()
			},
			// getCitys(type) {
			// 	// 获取可选地区列表
			// 	return this.$u.post('/User/Statistics/GetAreaCitys',{
			// 		type: type,
			// 		typeId: this.typeId
			// 	}).then((res) => {
			// 		console.log('获取可选地区列表', res)
			// 		let datas = []
			// 		res.forEach((item)=>{
			// 			datas.push({
			// 				value: item.id,
			// 				label: item.name
			// 			})
			// 		})
			// 		this.cityArr = datas
			// 	})
			// },
			getDataBoardDetails(renew = true){
				this.loadStatus = 'loading'
				if(renew == true){
					this.PageIndex = 1
					this.orderList = []
				}
				return this.$u.post('/Statistics/AppBigData/List',{
					PageIndex: this.PageIndex,
					PageSize: this.PageSize,
					key: this.key,
					id: this.id,
					type: this.type,
					timeType: this.timeType,
					startDate: this.startDate,
					endDate: this.endDate,
					cityId: this.cityId,
					enterprisetype: this.enterprisetype
				}).then((res) => {
					console.log('获取订单列表', res)
					if (res.rows.length > 0) {
						res.rows.forEach((item) => {
							this.orderList.push(item)
						})
						if (res.rows.length < this.PageSize) {
							this.loadStatus = "nomore"
						} else {
							this.loadStatus = "loadmore"
						}
					}else{
						this.loadStatus = "nomore"
					}
				})
			},
			// 查看详情
			goDetails(res){
				// return res.ordertype == '线下'?'/pages/my/order/fitviews/fitviews?id='+res.id:'/pages/my/order/views/views?id='+res.id
				let type
				if(res.ordertype == '线上'){
					type = 2
				}else{
					type = 1
				}
				return '/pages/my/board/order/views/views?id='+res.id+'&type='+type
			}
		}
	}
</script>

<style lang="scss" scoped>
	.total-weight {
		position: relative;
		margin-top: 0;
	
		.cell {
			padding: 10px 0;
			border-radius: 12rpx;
			display: flex;
			flex-direction: column;
			text-align: center;
		}
	
		.number {
			margin-top: 0;
			margin-bottom: 10rpx;
		}
	
		.divider {
			// width: 1rpx;
			height: 80rpx;
			background-color: #f1f1f1;
			margin: 0 10rpx;
		}
	}
	
	// 宫格展示
	.grid-box {
		background-color: #fff;
		margin: 0 30rpx;
		padding: 30rpx;
		border-radius: 12rpx;
		margin-top: 30rpx;
	
		.title {
			font-size: 28rpx;
			color: $u-tips-color;
		}
	
		.number {
			margin-top: 10rpx;
		}
	}
	
	// 筛选
	.filter-bar{
		background: #f2f2f2;
		height: 64rpx;
		line-height: 64rpx;
		padding: 0 20rpx;
		border-radius: 10rpx;
	}
	
	.order {
		background-color: #ffffff;
		margin: 30rpx;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;
	
		.top {
			display: flex;
			justify-content: space-between;
	
			.left {
				display: flex;
				align-items: center;
	
				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					// font-weight: bold;
					display: flex;
					align-items: center;
				}
			}
	
			.right {
				color: $u-type-warning-dark;
			}
		}
	
		.item {
			display: flex;
			margin: 20rpx 0 0;
			justify-content: space-between;
	
			.left {
				margin-right: 20rpx;
	
				image {
					width: 160rpx;
					height: 160rpx;
					border-radius: 10rpx;
				}
			}
	
			.content {
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
					font-weight: bold;
				}
	
				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}
	
				.delivery-time {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
	
			.right {
				margin-left: 10rpx;
				// padding-top: 20rpx;
				text-align: right;
	
				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}
	
				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}
	
		.total {
			text-align: right;
			font-size: 24rpx;
	
			.total-price {
				font-size: 32rpx;
				color: $u-color-orange;
			}
		}
	
		.time {
			font-size: 24rpx;
			margin: 20rpx 0;
			line-height: 40rpx;
		}
	
		.bottom {
			display: flex;
			margin-top: 40rpx;
			justify-content: space-between;
			align-items: center;
			.more{
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}
	
			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}
</style>
